<?php
/**
 * Created by PhpStorm.
 * User: zhj
 * Date: 2019/3/7
 * Time: 13:59
 */

namespace app\index\controller;

/**
 * 前端首页控制器
 */
class Foods extends IndexBase
{

    public function index()
    {
        $where['status'] = 1;
        $city_id = session('city_id');
        $cate_id = input('cate_id') ? input('cate_id') : 0;
        //先找出该城市下所有的城市
        $city_id and  $city_ids = $this->logicCity->getCityList(['pid'=>$city_id])->toArray();
        $city_ids = array_column($city_ids,'id');
        array_push($city_ids,(int)$city_id);
        $where['city_id'] = ['in',$city_ids];
        $list = $this->logicFoods->getFoodsList($where,'id,name,cover_id','id desc',9);
        $this->assign('list',$list);
        return $this->fetch('index');
    }

    // 详情
    public function details($id = 41)
    {

        $where = [];

        !empty((int)$id) && $where['id'] = $id;

        $data = $this->logicFoods->getFoodsInfo($where);
        $foods_list = $this->logicFoods->getFoodsList([],'id,name,cover_id',' RAND() ');
        $this->assign('foods_list',$foods_list->toArray()['data']);
        $data['content'] = html_entity_decode($data['content']);
        $this->assign('foods_info', $data);
        return $this->fetch('details');
    }

}